<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8">
            <a-form-model-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xm">
              <a-input v-model="model.xm" placeholder="请输入姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfzh">
              <a-input v-model="model.sfzh" placeholder="请输入身份证号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xb">
              <a-input v-model="model.xb" placeholder="请输入性别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="出生年月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="csny">
              <a-input v-model="model.csny" placeholder="请输入出生年月"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="民族" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mz">
              <a-input v-model="model.mz" placeholder="请输入民族"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="入伍时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rwsj">
              <j-date placeholder="请选择入伍时间" v-model="model.rwsj"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="退伍时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="twsj">
              <j-date placeholder="请选择退伍时间" v-model="model.twsj"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="政治面貌" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zzmm">
              <a-input v-model="model.zzmm" placeholder="请输入政治面貌"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="入党时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdsj">
              <j-date placeholder="请选择入党时间" v-model="model.rdsj"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lxdh">
              <a-input v-model="model.lxdh" placeholder="请输入联系电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="学历情况" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xlqk">
              <a-input v-model="model.xlqk" placeholder="请输入学历情况"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="拟安置地" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nazd">
              <a-input v-model="model.nazd" placeholder="请输入拟安置地"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="健康状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jkzt">
              <a-input v-model="model.jkzt" placeholder="请输入健康状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="残疾性质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cjxz">
              <a-input v-model="model.cjxz" placeholder="请输入残疾性质"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="入伍地" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rwd">
              <a-input v-model="model.rwd" placeholder="请输入入伍地"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="部队代号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bddh">
              <a-input v-model="model.bddh" placeholder="请输入部队代号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="退伍证号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="twzh">
              <a-input v-model="model.twzh" placeholder="请输入退伍证号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="安置方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="azfs">
              <a-input v-model="model.azfs" placeholder="请输入安置方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="军龄" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jl">
              <a-input v-model="model.jl" placeholder="请输入军龄"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="入伍高校名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rwgxmc">
              <a-input v-model="model.rwgxmc" placeholder="请输入入伍高校名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="是否复学" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffx">
              <a-input v-model="model.sffx" placeholder="请输入是否复学"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="奖惩信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jlxx">
              <a-input v-model="model.jlxx" placeholder="请输入奖惩信息"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'DaRyxxForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/dary/daRyxx/add",
          edit: "/dary/daRyxx/edit",
          queryById: "/dary/daRyxx/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>